package com.mis.pos.service.impl;

import com.mis.pos.dto.InventoryDTO;
import com.mis.pos.entity.InventoryEntity;
import com.mis.pos.form.ItemSearchForm;
import com.mis.pos.repository.InventoryRepository;
import com.mis.pos.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.transaction.Transactional;
import java.util.List;

/**
 * @Description
 * @Author yuxiang
 * @CreatedDate 2019/11/26 9:30
 */
@Service
public class InventoryServiceImpl implements InventoryService {
    @Autowired
    private InventoryRepository inventoryRepository;

    @Override
    public List<InventoryDTO> listInventory(ItemSearchForm searchForm, Integer pageNumber, Integer pageSize) {

        return null;
    }

    @Override
    public int saveInventory(List<InventoryEntity> entities) {
        try {
            inventoryRepository.saveAll(entities);
        }catch (Exception e){
            e.printStackTrace();
            return -1;
        }

        return 0;
    }

    @Override
    public int updateInventory(InventoryEntity entity) {
        try {
            inventoryRepository.save(entity);
        }catch (Exception e){
            e.printStackTrace();
            return -1;
        }
        return 0;
    }

    @Override
    public int changeInventory(Long itemId, Long number) {
        try {
            inventoryRepository.updateInventoryNumberByItemId(itemId,number);
        }catch (Exception e){
            e.printStackTrace();
            return -1;
        }
        return 0;
    }

    @Override
    public int addInventory(Long itemId, Long number) {
        try {
            inventoryRepository.addInventoryNumberByItemId(itemId,number);
        }catch (Exception e){
            e.printStackTrace();
            return -1;
        }
        return 0;
    }
}
